package com.suian.spring;

import com.suian.spring.entity.User;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(classes = Application.class)
class MyConfigRunner {

    @Autowired
    User user;

    @Autowired
    ApplicationContext applicationContext;
    @Test
    public void testGetBean() {
        System.out.println(user+"  "+user.getUsername());
        User u1 = (User) applicationContext.getBean("user");
        System.out.println(u1+"  "+u1.getUsername());
    }

    @Test
    public void testGetAllBeans() {
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanName : beanDefinitionNames) {
            if (applicationContext.getBean(beanName).getClass().getName().contains("suian")) {
                System.out.println(beanName + " -> " + applicationContext.getBean(beanName).getClass().getName());
            }

        }
    }

    @Test
    void fun1() {
//        new AbstractAutoProxyCreator()
//        BeanPostProcessor
    }

}